package daosimp;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import util1.HibernateUtil;
import modelo.Curso;
import daos.CursoDAO;

public class CursoDAOIMP implements CursoDAO{

	private Transaction tx;
	
	public Transaction getTx() {
		return tx;
	}

	public void setTx(Transaction tx) {
		this.tx = tx;
	}

	@Override
	public List<Curso> obtenerCursos(){
		List<Curso> cursos = new ArrayList<Curso>();
		try{
			tx = HibernateUtil.session.beginTransaction();
			String hql = "FROM Curso";
			Query query = HibernateUtil.session.createQuery(hql);
			if (!query.list().isEmpty()){
				cursos = query.list();
			}
			tx.commit();
		} catch(Exception ex){
			tx.rollback();
		}
		return cursos;
	}

}
